﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InSys.Documents
{
    using System.Windows.Forms;
    //Declare a class that inherits from ToolStripControlHost.
    public class ToolStripDateTimePicker : ToolStripControlHost
    {
        // Call the base constructor passing in a MonthCalendar instance.
        public ToolStripDateTimePicker() : base(new DateTimePicker()) { }

        public DateTimePicker MonthCalendarControl
        {
            get
            {
                return Control as DateTimePicker;
            }
        }

        //// Expose the MonthCalendar.FirstDayOfWeek as a property.
        //public Day FirstDayOfWeek
        //{
        //    get
        //    {
        //        return MonthCalendarControl.FirstDayOfWeek;
        //    }
        //    set { value = MonthCalendarControl.FirstDayOfWeek; }
        //}

        //// Expose the AddBoldedDate method.
        //public void AddBoldedDate(DateTime dateToBold)
        //{
        //    MonthCalendarControl.AddBoldedDate(dateToBold);
        //}

        // Subscribe and unsubscribe the control events you wish to expose.
        protected override void OnSubscribeControlEvents(Control c)
        {
            // Call the base so the base events are connected.
            base.OnSubscribeControlEvents(c);

            // Cast the control to a MonthCalendar control.
            DateTimePicker monthCalendarControl = (DateTimePicker)c;

            // Add the event.
            monthCalendarControl.ValueChanged += new EventHandler(monthCalendarControl_ValueChanged);
        }

        void monthCalendarControl_ValueChanged(object sender, EventArgs e)
        {
            if (DateChanged != null)
            {
                DateChanged(this, e);
            }
        }

        protected override void OnUnsubscribeControlEvents(Control c)
        {
            // Call the base method so the basic events are unsubscribed.
            base.OnUnsubscribeControlEvents(c);

            // Cast the control to a MonthCalendar control.
            DateTimePicker monthCalendarControl = (DateTimePicker)c;

            // Remove the event.
            monthCalendarControl.ValueChanged -=
                new EventHandler(monthCalendarControl_ValueChanged);
        }

        // Declare the DateChanged event.
        public event EventHandler DateChanged;

    }
}
